package com.tangyuan.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;


/**
 * @author 小梁
 * @since 2020-12-03
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="UserLike对象", description="")
@Slf4j
public class UserLike implements Serializable {

    @ApiModelProperty(value = "用户Id")
    @TableId(value = "user_id", type = IdType.AUTO)
    private Long userId;
    @ApiModelProperty(value = "影视")
    private float typeTelevisionValue;
    @ApiModelProperty(value = "搞笑")
    private float typeFunnyValue;
    @ApiModelProperty(value = "动漫")
    private float typeAnimeValue;
    @ApiModelProperty(value = "军事")
    private float typeMilitaryValue;
    @ApiModelProperty(value = "游戏")
    private float typeGameValue;
    @ApiModelProperty(value = "美食")
    private float typeFoodValue;
    @ApiModelProperty(value = "综艺")
    private float typeVarietyValue;
    @ApiModelProperty(value = "娱乐")
    private float typeEntertainmentValue;
    @ApiModelProperty(value = "生活")
    private float typeLifeValue;
    @ApiModelProperty(value = "放映厅")
    private float typeScreeningValue;
    @ApiModelProperty(value = "讲说人")
    private float typePeopleValue;
    @ApiModelProperty(value = "音乐")
    private float typeMusicValue;
    @ApiModelProperty(value = "广场舞")
    private float typeSquareValue;
    @ApiModelProperty(value = "宠物")
    private float typePetsValue;
    @ApiModelProperty(value = "三农")
    private float typeFarmersValue;
    @ApiModelProperty(value = "社会")
    private float typeSocietyValue;
    @ApiModelProperty(value = "科技")
    private float typeScienceValue;
    @ApiModelProperty(value = "时尚")
    private float typeFashionValue;
    @ApiModelProperty(value = "汽车")
    private float typeAutomobileValue;
    @ApiModelProperty(value = "亲子")
    private float typeRelationshipValue;
    @ApiModelProperty(value = "文化")
    private float typeCultureValue;
    @ApiModelProperty(value = "旅游")
    private float typeTravelValue;
    @ApiModelProperty(value = "秒懂")
    private float typeUnderstandingValue;
    @ApiModelProperty(value = "美女")
    private float typeBelleValue;

    @ApiModelProperty(value = "导游")
    private float typeGuideValue;

    @ApiModelProperty(value = "书画院")
    private float typePaintingandcalligraphyValue;

    @ApiModelProperty(value = "大舞台")
    private float typeBigstageValue;

    private static final long serialVersionUID = 1L;
    private static final Map<Integer,String> map = new HashMap<>();
    static {
        int y = 1;
        Field[] fields = UserLike.class.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if(fields[i].getName().equals("serialVersionUID")
            || fields[i].getName().equals("map")
            || fields[i].getName().equals("log")
            || fields[i].getName().equals("userId")
            ){
                continue;
            }
            map.put(y,fields[i].getName());
            y++;
        }
    }

    public static int getMethodCount() {
        return map.keySet().size() - 1;
    }

    public static void setMethod(UserLike userLike, int index, float value) {
        try {
            Class<? extends UserLike> aClass = userLike.getClass();
            Field field = aClass.getDeclaredField(map.get(index));
            field.setAccessible(true);
            field.set(userLike,value);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static float getMethod(UserLike userLike,int index) {
        try {
            Class<? extends UserLike> aClass = userLike.getClass();
            Field field = aClass.getDeclaredField(map.get(index));
            field.setAccessible(true);
            return field.get(userLike) == null ? 0f : Float.parseFloat(field.get(userLike).toString())  ;
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0f;
    }

    /**
     * 获取最大的type
     */
    public static int getMaxMethod(UserLike userLike) {
        if(userLike == null){
            log.error("userLike对象为空");
            return 0;
        }
        try {
            float value = 0f;
            int index = 0;

            for (Integer i : map.keySet()) {
                String s = map.get(i);
                if(s == null){
                    continue;
                }
                Field field = userLike.getClass().getDeclaredField(s);
                field.setAccessible(true);
                float f = field.get(userLike) == null ? 0f : Float.parseFloat(field.get(userLike).toString());
                if(f > value){
                    index = i;
                }
            }
            return index;
        }catch (Exception e){
            e.printStackTrace();
            log.error("userLike获取最大类型异常,userId:{},异常:{}",userLike.getUserId(),e.toString());
        }
        return 0;
    }

    public UserLike(Long userId) {
        this.userId = userId;
        this.typeTelevisionValue = 0f;
        this.typeFunnyValue = 0f;
        this.typeAnimeValue = 0f;
        this.typeMilitaryValue = 0f;
        this.typeGameValue = 0f;
        this.typeFoodValue = 0f;
        this.typeVarietyValue = 0f;
        this.typeEntertainmentValue = 0f;
        this.typeLifeValue = 0f;
        this.typeScreeningValue = 0f;
        this.typePeopleValue = 0f;
        this.typeMusicValue = 0f;
        this.typeSquareValue = 0f;
        this.typePetsValue = 0f;
        this.typeFarmersValue = 0f;
        this.typeSocietyValue = 0f;
        this.typeScienceValue = 0f;
        this.typeFashionValue = 0f;
        this.typeAutomobileValue = 0f;
        this.typeRelationshipValue = 0f;
        this.typeCultureValue = 0f;
        this.typeTravelValue = 0f;
        this.typeUnderstandingValue = 0f;
        this.typeBelleValue = 0f;
        this.typeGuideValue = 0f;
        this.typePaintingandcalligraphyValue = 0f;
        this.typeBigstageValue = 0f;
    }

    public void accumulateTelevisionValue() {
        if (this.typeTelevisionValue == 0.0F) {
            this.typeTelevisionValue = 5F;
        } else {
            this.typeTelevisionValue += 5F;
        }
    }
    public void accumulateFunnyValue() {
        if (this.typeFunnyValue == 0.0F) {
            this.typeFunnyValue = 5F;
        } else {
            this.typeFunnyValue += 5F;
        }
    }
    public void accumulateAnimeValue() {
        if (this.typeAnimeValue == 0.0F) {
            this.typeAnimeValue = 5F;
        } else {
            this.typeAnimeValue += 5F;
        }
    }
    public void accumulateMilitaryValue() {
        if (this.typeMilitaryValue == 0.0F) {
            this.typeMilitaryValue = 5F;
        } else {
            this.typeMilitaryValue += 5F;
        }
    }
    public void accumulateGameValue() {
        if (this.typeGameValue == 0.0F) {
            this.typeGameValue = 5F;
        } else {
            this.typeGameValue += 5F;
        }
    }
    public void accumulateFoodValue() {
        if (this.typeFoodValue == 0.0F) {
            this.typeFoodValue = 5F;
        } else {
            this.typeFoodValue += 5F;
        }
    }
    public void accumulateVarietyValue() {
        if (this.typeVarietyValue == 0.0F) {
            this.typeVarietyValue = 5F;
        } else {
            this.typeVarietyValue += 5F;
        }
    }
    public void accumulateEntertainmentValue() {
        if (this.typeEntertainmentValue == 0.0F) {
            this.typeEntertainmentValue = 5F;
        } else {
            this.typeEntertainmentValue += 5F;
        }
    }
    public void accumulateLifeValue() {
        if (this.typeLifeValue == 0.0F) {
            this.typeLifeValue = 5F;
        } else {
            this.typeLifeValue += 5F;
        }
    }
    public void accumulateScreeningValue() {
        if (this.typeScreeningValue == 0.0F) {
            this.typeScreeningValue = 5F;
        } else {
            this.typeScreeningValue += 5F;
        }
    }
    public void accumulatePeopleValue() {
        if (this.typePeopleValue == 0.0F) {
            this.typePeopleValue = 5F;
        } else {
            this.typePeopleValue += 5F;
        }
    }
    public void accumulateMusicValue() {
        if (this.typeMusicValue == 0.0F) {
            this.typeMusicValue = 5F;
        } else {
            this.typeMusicValue += 5F;
        }
    }
    public void accumulateSquareValue() {
        if (this.typeSquareValue == 0.0F) {
            this.typeSquareValue = 5F;
        } else {
            this.typeSquareValue += 5F;
        }
    }
    public void accumulatePetsValue() {
        if (this.typePetsValue == 0.0F) {
            this.typePetsValue = 5F;
        } else {
            this.typePetsValue += 5F;
        }
    }
    public void accumulateFarmersValue() {
        if (this.typeFarmersValue == 0.0F) {
            this.typeFarmersValue = 5F;
        } else {
            this.typeFarmersValue += 5F;
        }
    }
    public void accumulateSocietyValue() {
        if (this.typeSocietyValue == 0.0F) {
            this.typeSocietyValue = 5F;
        } else {
            this.typeSocietyValue += 5F;
        }
    }
    public void accumulateScienceValue() {
        if (this.typeScienceValue == 0.0F) {
            this.typeScienceValue = 5F;
        } else {
            this.typeScienceValue += 5F;
        }
    }
    public void accumulateFashionValue() {
        if (this.typeFashionValue == 0.0F) {
            this.typeFashionValue = 5F;
        } else {
            this.typeFashionValue += 5F;
        }
    }
    public void accumulateAutomobileValue() {
        if (this.typeAutomobileValue == 0.0F) {
            this.typeAutomobileValue = 5F;
        } else {
            this.typeAutomobileValue += 5F;
        }
    }
    public void accumulateRelationshipValue() {
        if (this.typeRelationshipValue == 0.0F) {
            this.typeRelationshipValue = 5F;
        } else {
            this.typeRelationshipValue += 5F;
        }
    }
    public void accumulateCultureValue() {
        if (this.typeCultureValue == 0.0F) {
            this.typeCultureValue = 5F;
        } else {
            this.typeCultureValue += 5F;
        }
    }
    public void accumulateTravelValue() {
        if (this.typeTravelValue == 0.0F) {
            this.typeTravelValue = 5F;
        } else {
            this.typeTravelValue += 5F;
        }
    }
    public void accumulateUnderstandingValue() {
        if (this.typeUnderstandingValue == 0.0F) {
            this.typeUnderstandingValue = 5F;
        } else {
            this.typeUnderstandingValue += 5F;
        }
    }
    public void accumulateBelleValue() {
        if (this.typeBelleValue == 0.0F) {
            this.typeBelleValue = 5F;
        } else {
            this.typeBelleValue += 5F;
        }
    }
    public void accumulateGuideValue() {
        if (this.typeGuideValue == 0.0F) {
            this.typeGuideValue = 5F;
        } else {
            this.typeGuideValue += 5F;
        }
    }
    public void accumulatePaintingAndCalligraphyValue() {
        if (this.typePaintingandcalligraphyValue == 0.0F) {
            this.typePaintingandcalligraphyValue = 5F;
        } else {
            this.typePaintingandcalligraphyValue += 5F;
        }
    }

    public void accumulateBigStageValue() {
        if (this.typeBigstageValue == 0.0F) {
            this.typeBigstageValue = 5F;
        } else {
            this.typeBigstageValue += 5F;
        }
    }
}
